package com.lee.auth.security.config;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;

/**
 * @author lee HN
 * @date 2021/4/12 15:11
 */
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public final class PathSecurity {

    private final List<PathHandler> handlerList = new ArrayList<>();

    private static final PathHandler[] EMPTY_HANDLER = new PathHandler[0];

    public PathSecurity addPathHandler(BiConsumer<HttpServletRequest, HttpServletResponse> handler, String... patterns) {
        handlerList.add(new PathHandler(handler, patterns));
        return this;
    }

    protected PathHandler[] handlers() {
        return handlerList.toArray(EMPTY_HANDLER);
    }

}
